package com.example.costumview.customview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.Nullable;

public class NormalGestureTackView extends View {

    private final Paint mPaint;

    private Path mPath;

    public NormalGestureTackView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint();
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(8);

        mPath=new Path();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawPath(mPath,mPaint);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction()==MotionEvent.ACTION_DOWN){
            mPath.moveTo(event.getX(),event.getY());
            invalidate();
            return true;
        }else if (event.getAction()==MotionEvent.ACTION_MOVE){
            mPath.lineTo(event.getX(),event.getY());
            invalidate();
        }
        return super.onTouchEvent(event);
    }
}
